package com.ruoyi.machine.advanced.repair.apply.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.machine.advanced.repair.apply.domain.RepairApply;
import com.ruoyi.machine.advanced.repair.apply.mapper.RepairApplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备维修申请表
 * 业务层处理
 */
@Service
public class RepairApplyService implements IRepairApplyService {

    @Autowired
    private RepairApplyMapper repairApplyMapper;

    /**
     * 查找设备维修申请表
     * @param repairApply
     * @return
     */
    @Override
    public List<RepairApply> selectRepairApplyList(RepairApply repairApply) {
        return repairApplyMapper.selectRepairApplyList(repairApply);
    }

    /**
     * 根据Id查找设备维修申请表
     * @param repairApplyId
     * @return
     */
    @Override
    public RepairApply selectRepairApplyById(String repairApplyId) {
        return repairApplyMapper.selectRepairApplyById(repairApplyId);
    }

    /**
     * 添加设备维修申请表
     * @param repairApply
     * @return
     */
    @Override
    public int insertRepairApply(RepairApply repairApply) {
        if (StringUtils.isNotNull(repairApplyMapper.selectRepairApplyById(repairApply.getRepairApplyId()))) {
            //存在
            return 0;
        }
        //不存在
        return repairApplyMapper.insertRepairApply(repairApply);
    }

    /**
     * 更新设备维修申请表
     * @param repairApply
     * @return
     */
    @Override
    public int updateRepairApply(RepairApply repairApply) {
        if (!StringUtils.isNotNull(repairApplyMapper.selectRepairApplyById(repairApply.getRepairApplyId()))) {
            //不存在
            return 0;
        }
        //存在
        return repairApplyMapper.updateRepairApply(repairApply);
    }

    /**
     * 删除设备维修申请表
     * 仅修改删除标志
     * @param repairApply
     * @return
     */
    @Override
    public int updateRepairApplyDeleteFlag(RepairApply repairApply) {
        return repairApplyMapper.updateRepairApplyDeleteFlag(repairApply);
    }
}
